﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Cemit.NetFramework.Demo
{
    [Obsolete("已过时，使用帧同步框架进行按键同步")]
    public class PolyPlayer : MonoBehaviour
    {
        public PolyPlayerData playerData;
        public PolyInput netInput;
        public Canvas ui;

        // Start is called before the first frame update
        void Start()
        {
            ui.worldCamera = Camera.main;
        }

        // Update is called once per frame
        void Update()
        {
            if (netInput != null)
            {
                Move();
            }
        }

        private void Move()
        {
            if (netInput.GetKey(KeyCode.W))
            {
                transform.Translate(Vector3.forward * Time.deltaTime, Space.Self);
            }
            if (netInput.GetKey(KeyCode.S))
            {
                transform.Translate(Vector3.back * Time.deltaTime, Space.Self);
            }
            if (netInput.GetKey(KeyCode.A))
            {
                transform.Translate(Vector3.left * Time.deltaTime, Space.Self);
            }
            if (netInput.GetKey(KeyCode.D))
            {
                transform.Translate(Vector3.right * Time.deltaTime, Space.Self);
            }
        }

        public void SetName(string name)
        {
            gameObject.name = name;
            ui.transform.Find("Name").GetComponent<Text>().text = name;
        }
    }
}